package net.oschina.arvin.sqlbuilder;

import net.oschina.arvin.sqlbuilder.definition.ColumnDefinition;

/**
 * Sql 参数
 *
 * @author Arvin
 * @time 2017/11/16 15:30
 */
public class SqlParam {

    /** 值 */
    private Object value;

    /** 参数类型 */
    private Class<?> paramType;

    /** 对应列定义 */
    private ColumnDefinition columnDefinition;

    public SqlParam(ColumnDefinition columnDefinition, Object value) {
        this.columnDefinition = columnDefinition;
        this.value = value;
        this.paramType = columnDefinition.getFieldType();
    }

    public SqlParam(Object value) {
        this.value = value;
        this.paramType = null == value ? null : value.getClass();
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    public Class<?> getParamType() {
        return paramType;
    }

    public String getParamTypeName() {
        return paramType == null ? null : paramType.getName();
    }

    public String getParamTypeSimpleName() {
        return paramType == null ? null : paramType.getSimpleName();
    }

    public void setParamType(Class<?> paramType) {
        this.paramType = paramType;
    }

    public ColumnDefinition getColumnDefinition() {
        return columnDefinition;
    }

    public void setColumnDefinition(ColumnDefinition columnDefinition) {
        this.columnDefinition = columnDefinition;
    }

    public String getModelFieldName() {
        return null != columnDefinition ? columnDefinition.getFieldName() : null;
    }

    public String getColumnName() {
        return null != columnDefinition ? columnDefinition.getUnWrapColumnName() : null;
    }
}
